package com.sailorj.medical.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

import com.sailorj.medical.domain.area.Area;
import com.sailorj.medical.domain.chronicdis.Chronicdis;
import com.sailorj.medical.domain.ill_card.Ill_card;
import com.sailorj.medical.exception.DbException;

public class Ill_cardDao extends GenericDao<Ill_card> {

	@Override
	protected Ill_card handle(ResultSet rs) throws SQLException {
		String ill_card_no = rs.getString("ill_card_no");
		String join_nh_code = rs.getString("join_nh_code");
		String IDcard = rs.getString("IDcard");
		String ill_code = rs.getString("ill_code");
		Timestamp start_day = rs.getTimestamp("start_day");
		Timestamp end_day = rs.getTimestamp("end_day");
		String areacode = rs.getString("areacode");
		String user_id = rs.getString("user_id");
		Area area = new Area(areacode);
		Chronicdis chronicdis = new Chronicdis(ill_code);
		Ill_card entity = new Ill_card(ill_card_no, join_nh_code, IDcard, ill_code, area, start_day, end_day, user_id,
				chronicdis);
		return entity;
	}

	/**
	 * 根据key 和 value(慢性病证编号)查询信息
	 */
	public List<Ill_card> findByKeyValue(String key, String value) throws DbException {
		try {
			String sqlSB = "";
			StringBuffer sb = new StringBuffer(1024);
			if (key != null && value != null) {
				sqlSB = sb.append(" and " + key + "='" + value + "'").toString();
			}
			String sql = "select * from t_ill_card where 1=1 " + sqlSB + "";

			Object[] params = {};

			return super.queryOjects(sql, params);

		} catch (SQLException e) {
			throw new DbException("慢性病证信息查询失败!", e);
		}
	}
}
